import Vue from "vue";
import Router from "vue-router";
import Layout from "@/views/layout/layout";
import Index from "@/views/home/index";
import Login from "@/views/login/login";

Vue.use(Router);
const router = new Router({
  routes: [
    {
      path: "/",
      name: "layout",
      component: Layout,
      redirect: { name: "index" },
      children: [
        // 首页
        {
          path: "/index",
          name: "index",
          component: Index,
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        {
          path: "/price",
          name: "price",
          component: () => import("@/views/price/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 关于我们
        {
          path: "/aboutUs",
          name: "aboutUs",
          // 重定向到首页并添加查询参数
          redirect: {
            name: "index",
            query: { aboutUs: "true" },
          },
        },
        // 联系我们
        {
          path: "/contactUs",
          name: "contactUs",
          // 重定向到首页并添加查询参数
          redirect: {
            name: "index",
            query: { contactUs: "true" },
          },
        },
        // 简易商城
        {
          path: "/easyShop",
          name: "easyShop",
          component: () => import("@/views/easyShop/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品中心
        {
          path: "/productCenter",
          name: "productCenter",
          component: () => import("@/views/productCenter/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品中心简易工作台
        {
          path: "/productSimpleWordbench",
          name: "productSimpleWordbench",
          component: () => import("@/views/productSimpleWordbench/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        //产品中心公众号智配中心

        {
          path: "/wechatAccountConfigure",
          name: "wechatAccountConfigure",
          component: () => import("@/views/wechatAccountConfigure/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 我的资源
        {
          path: "/myResources",
          name: "myResources",
          component: () => import("@/views/myResources/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },

        // 产品模版中心试用购买前
        {
          path: "/productTemplateBefore",
          name: "index",
          component: () => import("@/views/prodcutTemplateBefore/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品模版中心试用购买后
        {
          path: "/productTemplateAfter",
          name: "index",
          component: () => import("@/views/prodcutTemplateAfter/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 开启我的微官网试用前
        {
          path: "/productOpenstep",
          name: "productOpenstep",
          component: () => import("@/views/productOpenstep/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },

        // 产品中心试用购买前开启我的微官网
        {
          path: "/productOpenwecartBefore",
          name: "productOpenwecartBefore",
          component: () => import("@/views/productOpenwecartBefore/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品中心试用购买前开启我的微官网编辑
        {
          path: "/productOpenwecartBefore/Edit",
          name: "productOpenwecartBeforeEdit",
          component: () => import("@/views/productOpenwecartBefore/Edit/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },

        // 产品中心试用购买后开启我的微官网
        {
          path: "/productOpenwecartAfter",
          name: "productOpenwecartAfter",
          component: () => import("@/views/productOpenwecartAfter/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品中心购买后开启我的微官网
        {
          path: "/productOpenwecartAfter/admin/Edit",
          name: "productOpenwecartAfterAdminEdit",
          component: () =>
            import("@/views/productOpenwecartAfter/admin/Edit/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },

        // 产品中心购买订单
        {
          path: "/productTemplateOrder",
          name: "productTemplateOrder",
          component: () => import("@/views/productTemplateOrder/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 购物页面
        {
          path: "/shopping",
          name: "shopping",
          component: () => import("@/views/shopping/index"),
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
        // 产品介绍
        {
          path: "/productIntroduce",
          name: "productIntroduce",
          // 重定向到首页并添加查询参数
          redirect: {
            name: "index",
            query: { productIntroduce: "true" },
          },
          meta: {
            logoText: "",
            searchVisible: false,
          },
        },
      ],
    },
    // 登录页面路由 - 不使用Layout布局
    {
      path: "/login",
      name: "login",
      component: Login,
      meta: {
        guest: true, // 标记为游客可访问页面
        title: "i",
      },
    },
    // 预览页面路由 - 不使用Layout布局
    {
      path: "/preview",
      name: "preview",
      component: () => import("@/views/Preview/PreviewModal.vue"),
      meta: {
        guest: true, // 标记为游客可访问页面
        title: "i",
      },
    },
  ],
});

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

router.beforeEach((to, from, next) => {
  // cookie没有值就跳到登陆页
  // let area = sessionStorage.getItem('area')
  // if (area === null && to.name !== 'login' && to.name !== 'overview') {
  //   // Vue.prototype.$message.error('用户未登陆')
  //   next('/login')
  // } else {
  next();
  // }
});

export default router;
